<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ page import="java.util.*" %>
<%@ page import="com.augurit.wf.common.constant.WfConstant" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>制文</title>

	<!-- 引入基础的JS和CSS文件 -->
	<%@ include file="/common/meta.jsp"%>
<script src="${ctx}/resources/js/jquery/jquery.js" type="text/javascript"></script>
	<script language="JavaScript" src="${ctx}/resources/components/ntko/OfficeContorlFunctions.js"></script>
	<script language="JavaScript" src="${ctx}/gzcgwsp/wfex/client/common/js/wf-attachment-public.js"></script>	
	<script>
	
		
	
		 function clearNoNum(event,obj){ 
		     event = window.event||event; 
		     if(event.keyCode == 37 | event.keyCode == 39){ 
		         return; 
		     } 
		     obj.value = obj.value.replace(/[^\d.]/g,""); 
		     obj.value = obj.value.replace(/^\./g,""); 
		     obj.value = obj.value.replace(/\.{2,}/g,"."); 
		     obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
		 } 
		 function viewFileNum(){
			var fileCode='${requestScope.fileCode}';
			var templateCode='${templateCode}';
		 	var action="${ctx}/yw-print-doc!findFileNum.action?type=makedoc&fileCode="+fileCode+"&templateCode="+templateCode;
		 	window.open(action);
		 	
		 }
		 
	    function readTemplateFile(){
	      window.resizeTo(screen.availWidth,screen.availHeight);	 
          var filepath=document.getElementById("filepath").value;
          var url="${ctx}/bi/wf-template-print-ref-ex!readPrintZsFile.action?templateFilePath="+filepath;
          //alert(filepath);
          intializePage(url);          
       }
	          
       //保存
       function saveDocument(){
       	var fileNum=document.getElementById("fileNum").value;
       	if(fileNum==""){
       		alert("请输入文号");
       		return;
       	}
       	//检查
       	 var url="${ctx}/printDoc/yw-print-doc!checkData.action?templateCode=${templateCode}&ywId=${requestScope.entityId}&fileCode=${requestScope.fileCode}&fileNum="+fileNum;
       		$.ajax({
				url : url,
				type : "post",
				dataType : "html",
				success : function(msg) {
					if(msg=="fail"){
						if(confirm("制作补正材料通知没有保存告知相关信息，不填写告知信息将不启动暂停审批流程，确定保存吗？")){
							   var action =document.forms[0].action;
							  document.forms[0].action=action+"&bjgz=false";
							   saveDocumentToUrl();
						}else{
							return;
						}
					}else if(msg=="numdiff"){
						alert("文号不一致，请仔细检查");
						return;
					}else if(msg=="numExist"){
						alert("文号存在");
						return;
					}else　if(msg=="fileNumEmpty"){
						alert("请输入文号");
						return;
					}else{
						 saveDocumentToUrl();
					}
					
				},
				error:function() {
					alert("添加失败！请刷新重试！");
				}
			});
       }
		function setDefaultFileName(){
			var fileName = window.opener.document.forms[0].title.value;
			document.forms[0].fileName.value = fileName + ".doc";
		}
		
		function printRecord(){
			var obj = document.all.item("NTKO_OCX");
			<%
				Map<String, Object> map = (Map<String, Object>)request.getAttribute(WfConstant.PRINT_BUFFER);
					    	
				if(map != null){
					Iterator it = map.entrySet().iterator();
					while(it.hasNext()){
						Map.Entry<String, Object> entry = (Map.Entry<String, Object>)it.next();						
						String value = entry.getValue().toString();
						if( value.indexOf("\n") >= 0){
							value = value.replace("\n", "\\n");
							value = value.replace("\r", "\\r");
						}
			%> 
			            
						obj.SetbookmarkValue("<%=entry.getKey()%>", "<%=value%>");
			<%		
					}
				}
			%>
		}
		
		//制文
		function makeDocument(){
			var obj = document.all.item("NTKO_OCX");
			printRecord();

		}
		
		//ntko控件下载
       function ocxDownLoad(){
          location.href="${ctx}/resources/components/ntko.rar";
       }
		
</script>
</head>

<body onload="readTemplateFile();"   topmargin="0" leftmargin="0">
<form action="${ctx}/printDoc/yw-print-doc!saveMakeDocument.action?templateCode=${templateCode}&ywId=${requestScope.entityId}&fileCode=${requestScope.fileCode}&templateId=${requestScope.templateId}&isunified=${requestScope.isunified}" enctype="multipart/form-data" method="post">
    
    <!---------------- 隐藏域区域 开始 ----------------->
    <input type="hidden" id="isAttachmentContentChange" name="isAttachmentContentChange" value="${isAttachmentContentChange}"/>
	<input type="hidden" name="sysFileId" value="${sysFileId}"/>
	<input type="hidden" id="filepath" name="templateFilePath" value="${templateFilePath}"/>
	<!---------------- 隐藏域区域 结束 ----------------->
    
    <!---------------- 标题栏 开始 ----------------->
	<table class="tb_custom">
		<tr height="10"><td></td></tr>
		<tr>
			<td width="5" align="right"><img src="${ctx}/resources/images/icons/16_16/application_view_list.png" hspace="8"/></td>
			<td class="title">
				制文
			</td>
		</tr>
	</table>
	<table class="tb_custom" height="5">
		<tr><td height="3" background="${ctx}/resources/images/style/blue/bg_line.gif"></td></tr>
	</table>
	<!---------------- 标题栏 结束 ----------------->  
    <!---------------- 工具栏 开始 ----------------->
	<table class="tb_custom">
		<tr>
			<td width="20%" class="td_header_l">&nbsp;
				<input type="button" value=" 退 出 " onclick="window.close()"/>
				<input type="button" value=" 控件下载 " onclick="ocxDownLoad()"/>
			</td>
		</tr>
	</table>
	<!---------------- 工具栏 结束 ----------------->  
    <!---------------- 业务表单 开始 ----------------->
    <table class="tb_custom">
    	<tr>
			<td><input type="hidden" name="fileName" value="${fileName}" class="text"/></td>
				<!-- 在发文流程中，设置制文后的文件的fileType为“2” -->
  			<td><input type="hidden" name="fileType" value="2" class="text"/></td>
  				<!-- 在发文流程中，设置制文后的文件的format属性“doc” -->		
  			<td><input type="hidden" name="fileFormat" value="doc" class="text"/></td>
    	</tr>
	</table>	
	<table class="tb_custom">
		<tr>
    		<table class="td_header_l" width="100%"></table>
    		<script type="text/javascript" src="${ctx}/resources/components/ntko/genOfficeControl.js"></script> 
			<script language="javascript" for=NTKO_OCX event="OnDocumentOpened(TANGER_OCX_str,TANGER_OCX_obj)">
				//setDefaultStateOnMakeDocument();
				makeDocument();
				//OFFICE_CONTROL_OBJ.SetReadOnly(false);
				setFileOpenedOrClosed(true);
		        printRecord();
			</script>
			<script language="JScript" for=NTKO_OCX event="OnDocumentClosed()">
				setFileOpenedOrClosed(false);
			</script>			
    	</tr>		
	</table>
	<!---------------- 业务表单 结束 -------------------->
	<!---------------- 工具栏 开始 ----------------->
	<table class="tb_custom">
		<tr>
			<td class="td_header">&nbsp;
				<input type="button" value=" 保 存 " onclick="saveDocumentToUrl()"/>&nbsp;
				<input type="button" value=" 退 出 " onclick="window.close()"/>
			</td>
		</tr>
	</table>
	<!---------------- 工具栏 结束 ----------------->	
</form>
</body>
</html>

